package com.oceantrader.sale.commons.config.datasource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.oceantrader.root.tools.Dao;
import com.oceantrader.root.tools.Dao2;
import com.oceantrader.root.tools.Dao2Impl;
import com.oceantrader.root.tools.DaoImpl;

import io.vertx.mysqlclient.MySQLBuilder;
import io.vertx.mysqlclient.MySQLConnectOptions;
import io.vertx.sqlclient.Pool;
import io.vertx.sqlclient.PoolOptions;
import lombok.RequiredArgsConstructor;

/**
 * 数据源配置
 * 
 * @author xuesinuo
 */
@Configuration
@RequiredArgsConstructor
public class DataSourceConfiguration {
    @Bean
    public Pool pool() {

        var mySQLConnectOptions = new MySQLConnectOptions()
                .setHost("127.0.0.1").setPort(3306)
                .setUser("root").setPassword("root")
                .setDatabase("ocean_trader_sale_test").setUseAffectedRows(true).setCharset("utf8mb4");
        var poolOptions = new PoolOptions().setMaxSize(1).setMaxWaitQueueSize(-1);
        Pool pool = MySQLBuilder.pool()
                .with(poolOptions)
                .connectingTo(mySQLConnectOptions)
                .build();
        return pool;
    }

    @Bean
    public Dao dao(Pool pool) {
        return new DaoImpl(pool);
    }

    @Bean
    public Dao2 dao2(Pool pool) {
        return new Dao2Impl(pool);
    }
}
